package archive

import (
	"time"

	"google.golang.org/protobuf/types/known/timestamppb"
)

// TimeToProtoTimestamp converts time.Time to protobuf Timestamp
func TimeToProtoTimestamp(t time.Time) *timestamppb.Timestamp {
	if t.IsZero() {
		return nil
	}
	return timestamppb.New(t)
}

// ProtoTimestampToTime converts protobuf Timestamp to time.Time
func ProtoTimestampToTime(ts *timestamppb.Timestamp) time.Time {
	if ts == nil {
		return time.Time{}
	}
	return ts.AsTime()
}

// NowTimestamp returns current time as protobuf Timestamp
func NowTimestamp() *timestamppb.Timestamp {
	return timestamppb.Now()
}

// IsZeroTime checks if time is zero value
func IsZeroTime(t time.Time) bool {
	return t.IsZero()
}
